// index.cpp : index
// 2009-09

#include "index.h"
#include "utils.h"

#include <stdio.h>
#include <string.h>
#include <assert.h>

struct indexs_t g_indexs;

indexs_t::~indexs_t()
{
	size = 0;
	if( NULL != data )
		delete [] data;
	data = NULL;
}

int indexs_t::LoadAllIndex( FILE *fp, size_t start, size_t num )
{
	assert( NULL != fp );
	// load from file
	unsigned char *buf = new unsigned char[num * 7];
	memset( buf, num * 7, 0 );
	size_t rc = 0;

	if( fseek( fp, start, SEEK_SET ) == 0 ) rc = fread( buf, num * 7, 1, fp );
	if( rc != 1 ) {
		delete [] buf;
		return -1;
	}

	// convert to indexs_t
	size = num;
	data = new struct index_t[num];
	for( size_t i = 0; i < num; i++ ) {
		memcpy( (void *)&data[i], (void *)&buf[i * 7], 7 );
	}

	return 0;
}

